package com.opages.mvc.demo.controller;

import com.opages.mvc.demo.api.MvcDemoApi;
import com.opages.mvc.demo.model.MvcDemoDto;
import com.opages.mvc.example.api.MvcExampleApi;
import com.opages.mvc.example.model.MvcExampleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MvcDemoController implements MvcDemoApi {
	@Autowired
	private MvcExampleApi mvcExampleApi;

	@Override
	public MvcDemoDto getDemo(@RequestParam("id") Integer id) {
		MvcDemoDto dto = new MvcDemoDto();
		dto.setId(1l);
		dto.setName("小明");
		dto.setWeight("200斤");
		return dto;
	}

	@Override
	public void save(@RequestBody MvcDemoDto demoDto) {
		System.err.println("保存->"+demoDto.toString());
	}

	@Override
	public MvcExampleDto getMvcExample(@RequestParam("id")Integer id) {
		MvcExampleDto demo = mvcExampleApi.getExample(id);
		MvcExampleDto exampleDto = new MvcExampleDto();
		exampleDto.setId(1);
		exampleDto.setPassword("123456");
		exampleDto.setUsername("name");
		System.err.println("MvcDemoController->"+exampleDto.toString());
		mvcExampleApi.save(exampleDto);
		System.err.println("demo-->"+demo);
		return demo;
	}
}
